package com.ysx.server.mapper;

import com.github.pagehelper.Page;
import com.ysx.server.pojo.dto.GoodsDTO;
import com.ysx.server.pojo.dto.GoodsPageQueryDTO;
import com.ysx.server.pojo.entity.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author ysx
* @description 针对表【goods(商品表)】的数据库操作Mapper
* @createDate 2024-02-14 19:59:06
* @Entity com/ysx/server/pojo.domain.Goods
*/
@Mapper
public interface GoodsMapper {
    /**
     * 商品动态查询
     * @param goodsPageQueryDTO
     * @return
     */
    Page<Goods> page(GoodsPageQueryDTO goodsPageQueryDTO);

    /**
     * 插入数据
     * @param goods
     * @return
     */
    boolean save(Goods goods);

    /**
     * 修改商品信息
     * @param goodsDTO
     * @return
     */
    boolean update(GoodsDTO goodsDTO);

    /**
     * 删除商品
     * @param id 用户id
     * @return
     */
    @Delete("delete from second_hand_trading.goods where id=#{id}")
    boolean delete(Long id);

    /**
     * 根据分类id查询
     * @param typeId
     * @return
     */
    @Select("select * from second_hand_trading.goods where typeId=#{typeId}")
    List<Goods> getByCategoryId(Long typeId);

    /**
     * 通过用户id查找商品
     * @return
     */
    @Select("select * from second_hand_trading.goods where userId=#{userId}")
    List<Goods> getByUserId(Long userId);

    /**
     * 获取最新时间商品
     * @return
     */
    @Select("select * from second_hand_trading.goods order by createTime desc limit 48")
    List<Goods> getByTime();

    /**
     * 通过名称搜索
     * @param name
     * @return
     */
    List<Goods> getByName(String name);

    /**
     * 通过id查找商品
     * @param id
     * @return
     */
    @Select("select * from second_hand_trading.goods where id=#{id}")
    Goods getById(Long id);

    /**
     * 获取所有商品
     * @return
     */
    @Select("select * from second_hand_trading.goods where goodsStatus=1")
    List<Goods> getAll();
}




